<template>
  <div id='should-login' class='con' @click.prevent='close()'>
    <div class='main' @click.prevent='handle'>
      <div class='title'>
        注册或登录后即可继续操作
      </div>
      <div v-if='!isWechat' id='bd-btn' class='btn' @click='goLogin'>
        使用帐号登录
      </div>
      <div v-if='isWechat' id='bd-wechat-btn' class='btn wechat' @click='goLogin'>
        使用微信快捷登录
      </div>
    </div>
  </div>
</template>

<script>
import { setTitle, isWechat, freeze } from '@/utils'
import Router from '@/router.js'

let lastTitle

export default {
  // props: ['path', 'backClose'],
  data () {
    return {
      isWechat: isWechat(),
    }
  },
  methods: {
    goLogin () {
      console.log(this.path)
      console.log(888)
      if (this.path) {
        // console.log(Router)
        Router.push(`/login?redirect=${this.path}`)
        // goAccountLogin('https://' + location.host + this.path)
      } else {
        // console.log(Router)
        Router.push('/login')

        // goAccountLogin()
      }
      this.close()
    },
    close (closeNow) {
      if (this.backClose || closeNow) {
        freeze(false)
        const ele = document.querySelector('#should-login')
        ele && ele.parentNode.removeChild(this.$el)
        document.querySelector('#app').classList.remove('blur')
        setTitle(lastTitle)
      }
    },
    handle (e) {
      e.stopPropagation()
    },
  },
  beforeMount () {
    lastTitle = document.title
    setTitle('注册或登录后即可继续操作')
    document.querySelector('#app').classList.add('blur')
    freeze()
  },
  beforeDestroy () {
    console.log(5656565)
    this.$shouldLogin.close()
    freeze(false)
  },
}
</script>
<style lang='scss' scoped>
.con {
  position: fixed;
  z-index: 1100;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
}

.main {
  width: 92%;
  max-width: 472px;
  padding: 25px 30px 20px;
  -webkit-transform: translate3d(-50%, -50%, 0);
  transform: translate3d(-50%, -50%, 0);
  position: absolute;
  z-index: 1101;
  top: 50%;
  left: 50%;
  bottom: auto;
  right: auto;
  overflow: auto;
  border: none;
  outline: none;
  background: #fff;
  border-radius: 4px;
  box-sizing: border-box;
  text-align: center;
}

.title {
  margin-bottom: 32px;
  font-size: 18px;
}

.btn {
  cursor: pointer;
  display: block;
  padding: 13px 0;
  width: 100%;
  font-size: 16px;
  background-color: #fa5746;
  color: #fff;
  border: 1px solid #fa5746;
  border-radius: 5px;
  margin-bottom: 10px;

  &:active {
    background-color: #fa9685;
    border-color: #fa9685;
  }
}

.wechat {
  background-color: #09bb07;
  border-color: #09bb07;

  &:active {
    background-color: #6ebb65;
    border-color: #6ebb65;
  }
}
</style>
